<?php

/*
 * Formulaire d'administration de la société
 */

class Application_Form_Societe extends Zend_Form
{
	private $base_url;
    public $descOption;
	
	/* Surcharge du constructeur */
	public function __construct($options = null, $base_url){		
		$this->base_url = $base_url;
        foreach ($options as $cle => $valeur) {
            $this->$cle = $valeur;
        }
		parent::__construct($options);
	}
	
	public function init()
	{
		/* Form Elements & Other Definitions Here ... */
		$this->setName('societe')
			 ->setAction($this->base_url.'/outils/societe') // ajouter Helper pour baseUrl plus helper de vue
			 ->setDisableLoadDefaultDecorators(true)
			 ->setAttrib('id','frm_societe')
			 ->setAttrib('class', 'form-horizontal');
             
        $id_societe = new Zend_Form_Element_Hidden('id_societe');
        
        $nom_societe = new Zend_Form_Element_Text('nom_societe');
        $nom_societe->setLabel('Nom de votre entreprise')
				->setRequired(true)
                ->setAttrib("class", "input-large")
                ->setAttrib("required", "required");
                
        $adresse_societe = new Zend_Form_Element_Textarea('adresse_societe');
        $adresse_societe->setLabel('Adresse')
            ->setAttrib('cols', '50')
            ->setAttrib('rows', '3')
            ->setAttrib("required", "required");
		
        $adresse_complementaire_societe = new Zend_Form_Element_Textarea('adresse_complementaire_societe');
        $adresse_complementaire_societe->setLabel("Complément d'adresse")
            ->setAttrib('cols', '50')
            ->setAttrib('rows', '3');
            
        $cp_societe = new Zend_Form_Element_Text('cp_societe');
        $cp_societe->setLabel('Code postal')
                ->setAttrib("class", "input-small")
                ->setAttrib("required", "required");
                
        $ville_societe = new Zend_Form_Element_Text('ville_societe');
        $ville_societe->setLabel('Ville')
                ->setAttrib("class", "input-large")
                ->setAttrib("required", "required");
        
        $siret_societe = new Zend_Form_Element_Text('siret_societe');
        $siret_societe->setLabel('N° SIRET')
                ->setAttrib("class", "input-large")
                ->setAttrib("required", "required");
                
        $id_tva = new Zend_Form_Element_Select('id_tva');
        $id_tva->setLabel('TVA')
            ->setAttrib("required", "required")
			->setAttrib("class", "span2")
            ->setMultiOptions($this->descOption);
        
        $submit = new Zend_Form_Element_Submit('submit');
		$submit->setLabel('Enregistrer')
				->setAttrib('class', 'btn btn-primary');
				
		$this->addElements(array($id_societe, $nom_societe, $adresse_societe,
                                 $adresse_complementaire_societe, $cp_societe,
                                 $ville_societe, $siret_societe, $id_tva, $submit));
    }
    
    public function render(Zend_View_Interface $view=null){
        
        $liste_elements = $this->getElements();
		$html='';
		
		$html .= "<form id='" . $this->getAttrib('id') . "' action='" . $this->getAction() . "' method='" . $this->getMethod() . "' class='" . $this->getAttrib("class") . "'>";


		$html .= '<div class="control-group">';
		
        $html .= '<label class="control-label" for="'.$liste_elements['nom_societe']->getName().'">';
        $html .= $liste_elements['nom_societe']->getLabel().'</label>';
        $html .= '<div class="controls">';
		
        $html .= $liste_elements['id_societe']->renderViewHelper();
		$html .= $liste_elements['nom_societe']->renderViewHelper();

        $html.= '</div>';
        $html.= '</div>';

		$html .= '<div class="control-group">';
		
        $html .= '<label class="control-label" for="'.$liste_elements['adresse_societe']->getName().'">';
        $html .= $liste_elements['adresse_societe']->getLabel().'</label>';
        $html .= '<div class="controls">';
		
		$html .= $liste_elements['adresse_societe']->renderViewHelper();

        $html.= '</div>';
        $html.= '</div>';

		$html .= '<div class="control-group">';
		
        $html .= '<label class="control-label" for="'.$liste_elements['adresse_complementaire_societe']->getName().'">';
        $html .= $liste_elements['adresse_complementaire_societe']->getLabel().'</label>';
        $html .= '<div class="controls">';
		
		$html .= $liste_elements['adresse_complementaire_societe']->renderViewHelper();

        $html.= '</div>';
        $html.= '</div>';
		
		$html .= '<div class="control-group">';
		
        $html .= '<label class="control-label" for="'.$liste_elements['cp_societe']->getName().'">';
        $html .= $liste_elements['cp_societe']->getLabel().'</label>';
        $html .= '<div class="controls">';
		
		$html .= $liste_elements['cp_societe']->renderViewHelper();

        $html.= '</div>';
        $html.= '</div>';
		
		$html .= '<div class="control-group">';
		
        $html .= '<label class="control-label" for="'.$liste_elements['ville_societe']->getName().'">';
        $html .= $liste_elements['ville_societe']->getLabel().'</label>';
        $html .= '<div class="controls">';
		
		$html .= $liste_elements['ville_societe']->renderViewHelper();

        $html.= '</div>';
        $html.= '</div>';

		$html .= '<div class="control-group">';
        $html .= '<label class="control-label" for="'.$liste_elements['id_tva']->getName().'">';
        $html .= $liste_elements['id_tva']->getLabel().'</label>';
        $html .= '<div class="controls">';
		$html .= $liste_elements['id_tva']->renderViewHelper();

        $html.= '</div>';
        $html.= '</div>';
		
		$html .= '<div class="control-group">';
		
        $html .= '<label class="control-label" for="'.$liste_elements['siret_societe']->getName().'">';
        $html .= $liste_elements['siret_societe']->getLabel().'</label>';
        $html .= '<div class="controls">';
		
		$html .= $liste_elements['siret_societe']->renderViewHelper();

        $html.= '</div>';
        $html.= '</div>';
		
		$html .= $liste_elements['submit']->renderViewHelper();
        
        $html .= '</form>';
        $this->_setIsRendered();
		return $html;
    }
}